<%@ page import="org.ikastola.Receipt" %>
<!DOCTYPE html>
<html>
	<head>
		<meta name="layout" content="main">
		<g:set var="entityName" value="${message(code: 'receipt.label', default: 'Receipt')}" />
		<title><g:message code="default.show.label" args="[entityName]" /></title>
		<g:javascript library="jquery" plugin="jquery"/>
		<r:require module="jquery-ui"/>
	</head>
	<body>
		<script type="text/javascript">
			$(document).ready(function() {
				$(".tooltip").tooltip();
			});
			$.widget("ui.tooltip", $.ui.tooltip, {
			    options: {
			        content: function () {
			            return $(this).prop('title');
			        }
			    }
			});
		</script>
		<a href="#show-receipt" class="skip" tabindex="-1"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
		<div class="nav" role="navigation">
			<ul>
				<li><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></li>
				<li><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></li>
			</ul>
		</div>
		<div id="show-receipt" class="content scaffold-show" role="main">
			<h1><g:message code="default.show.label" args="[entityName]" />
				<g:if test="${receiptInstance?.student}">
					- <g:fieldValue bean="${receiptInstance?.student}" field="name"/> <g:fieldValue bean="${receiptInstance?.student}" field="lastname"/>
				</g:if>
			</h1>
			<g:if test="${flash.message}">
			<div class="message" role="status">${flash.message}</div>
			</g:if>
			<ol class="property-list receipt">
			
				<g:if test="${receiptInstance?.total}">
				<li class="fieldcontain">
					<span id="total-label" class="property-label" style="text-align:left;"><g:message code="receipt.total.label" default="Total" /></span>
					
						<span class="property-value" aria-labelledby="total-label"><g:fieldValue bean="${receiptInstance}" field="total"/></span>
					
				</li>
				</g:if>
				
				<li class="fieldcontain">
					<span id="total-label" class="property-label" style="text-align:left;"><g:message code="receipt.due.label" default="Due" /></span>
					
						<span class="property-value" aria-labelledby="due-label"><g:fieldValue bean="${receiptInstance}" field="due"/></span>
					
				</li>
			
				<g:if test="${receiptInstance?.creationdate}">
				<li class="fieldcontain">
					<span id="creationdate-label" class="property-label" style="text-align:left;"><g:message code="receipt.creationdate.label" default="Creationdate" /></span>
					
						<span class="property-value" aria-labelledby="creationdate-label"><g:formatDate date="${receiptInstance?.creationdate}" /></span>
					
				</li>
				</g:if>
				
<%--				<g:if test="${receiptInstance?.istemp}">--%>
<%--				<li class="fieldcontain">--%>
<%--					<span id="istemp-label" class="property-label" style="text-align:left;"><g:message code="receipt.istemp.label" default="Is Temp" /></span>--%>
<%--						<span class="property-value" aria-labelledby="istemp-label">--%>
<%--						<g:if test="${receiptInstance?.istemp == '1'}" ><g:message code="receipt.istemp.1" /></g:if>--%>
<%--						<g:else><g:message code="receipt.istemp.2" /></g:else>--%>
<%--						</span>--%>
<%--				</li>--%>
<%--				</g:if>--%>
			
				<g:if test="${receiptInstance?.checks}">
				<li class="fieldcontain">
					<span id="checks-label" class="property-label" style="text-align:left;"><g:message code="receipt.checks.label" default="Checks" /></span>
						<g:each in="${receiptInstance.checks}" var="c">
							<span class="property-value" aria-labelledby="checks-label"><g:link controller="paymentCheck" action="show" id="${c.id}">${c?.number?.encodeAsHTML()} - ${c?.bank?.encodeAsHTML()}</g:link></span>
						</g:each>
				</li>
				</g:if>
				
				<g:if test="${receiptInstance?.details}">
				<li class="fieldcontain">
					<table>
						<thead>
							<tr>
							<th><g:message code="receipt.items.description.label" /></th>
							<th><g:message code="receipt.items.paymentdate.label" default="Periodo" /></th>
							<th><g:message code="paymentCheck.amount.label" /> ($)</th>
							<th>Pagado ($)</th>
							</tr>
						</thead>
						<tbody>
						<g:each in="${receiptInstance.details}" status="i" var="d">
						<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
							<span class="property-value" aria-labelledby="details-label" >
								<g:if test="${d?.details}">
									<td class="tooltip" title="<g:each in='${d?.details}' var='fd'><b>${fd?.name}</b>:&nbsp;$${fd?.value}<br/></g:each>" >
								</g:if>
								<g:else><td></g:else>
								${d?.description?.encodeAsHTML()}
								</td>
								<td>
								<g:if test="${ikastola.Constants.FEE_PERIOD_MONTH.equals(d?.getPeriod())}">
									<g:formatDate date="${d?.paymentdate}" format="${ikastola.Constants.DATE_FORMAT_MONTH}"/>
								</g:if>
								<g:else>
									<g:formatDate date="${d?.paymentdate}" format="${ikastola.Constants.DATE_FORMAT_YEAR}"/>
								</g:else>
								</td>
								<g:if test="${ikastola.Constants.IS_DISCOUNT.equals(d?.getIsdiscount())}" >
									<td>-${d?.valueFee?.encodeAsHTML()}</td>
									<td>-</td>
								</g:if>
								<g:else>
									<td>${d?.valueFee?.encodeAsHTML()}</td>
									<td>${d?.value?.encodeAsHTML() }</td>
								</g:else>
							</span>
						</tr>	
						</g:each>
						</tbody>
					</table>
				</li>
				</g:if>			
	
			</ol>
			<g:form>
				<fieldset class="buttons">
					<g:hiddenField name="id" value="${receiptInstance?.id}" />
					<g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
					<g:link class="pdf" controller="receipt" action="pdf" id="${receiptInstance?.id}" >Descargar</g:link>
<%--				<g:jasperReport jasper="invoice" controller="receipt" action="pdf/${receiptInstance?.id}" format="pdf" name="recibo-${receiptInstance?.id}" description="Descargar" delimiter=" "/>--%>
				</fieldset>
			</g:form>
		</div>
	</body>
</html>
